<div class="layui-form seller-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm return-goods">< 返回商品</button>
        </div>
    </div>
</div>

<div class="table-body">
    <table id="CommentTable"></table>
</div>

<script>
    var table, window_box;
    layui.use(['form', 'layedit', 'laydate','table', 'layer'], function(){
        var layer = layui.layer;
        table = layui.table.render({
            elem: '#CommentTable',
            height: 'full-210',
            cellMinWidth: '80',
            page: 'true',
            limit: '20',
            url: "{:url('Goods/commentList')}?goods_id={$goods_id}",
            id: 'CommentTable',
            response: {
                statusName: 'status',
                statusCode: true
            },
            cols: [[
                {type:'numbers'},
                {field:'nickname', width:210, title:'用户昵称', align:'center'},
                {field:'evaluate', width:150, sort:true, title:'评价类型', align:'center'},
                {field:'content', width:150, sort:true, title:'评价内容', align:'center'},
                {field:'order_id', width:300, title:'订单号', align:'center'},
                {field:'ctime', width:230, sort:true, title:'评价时间', align:'center'},
                {field:'display', width:150, sort:true, title:'前台显示', align:'center', templet:function(data){
                        if(data.display === 1){
                            return '<a href="javascript:void(0);" class="display" data-id="'+data.id+'">隐藏</a>';
                        }else{
                            return '<a href="javascript:void(0);" class="display" data-id="'+data.id+'">显示</a>';
                        }
                }},
                {field:'operating', width:200, title:'操作', align:'center', templet:function(data){
                        var html = '';
                        //html += '<a class="layui-btn layui-btn-xs comment-show" data-id="' + data.id + '">查看评价</a>';
                        html += '<a class="layui-btn layui-btn-xs comment-return" data-id="' + data.id + '">评价回复</a>';
                        return html;
                }, fixed:'right'}
            ]]
        });

        //前台展示设置
        $(document).on("click", '.display', function () {
            var id = $(this).attr('data-id');
            layer.confirm('是否确认该操作？', {
                title: "提示",
                btn: ['是', '否']
            }, function () {
                JsPost("{:url('Goods/setDisplay')}",{'id':id},function(res){
                    layer.msg(res.msg);
                    layui.table.reload('CommentTable');
                });
            }, function(){
                layer.closeAll();
            });
        });

        //返回上个页面
        $(document).on("click", '.return-goods', function () {
            window.history.back();
        });

        //回复
        $(document).on("click", '.comment-return', function () {
            var id = $(this).attr('data-id');
            JsPost("{:url('Goods/getCommentInfo')}", {'id':id}, function(res) {
                if(res.status) {
                    var seller_content = res.data.seller_content == null?'':res.data.seller_content;
                    window_box = layer.open({
                        type: 1,
                        title: "商家回复",
                        area: ['450px', '300px'], //宽高
                        btn:['保存','关闭'],
                        content: '<div style="padding:20px"><input type="hidden" id="return-id" value="'+id+'">' +
                        '<div><span>用户评价：</span>'+res.data.content+'</div>' +
                        '<div><span>商家回复：</span><textarea class="layui-textarea" name="return-content" id="return-content" cols="10" rows="5">'+seller_content+'</textarea></div></div>',
                        yes:function () {
                            var id = $("#return-id").val();
                            var return_content = $("#return-content").val();
                            JsPost("{:url('Goods/sellerContent')}", {'id':id, "seller_content":return_content}, function(res) {
                                layer.closeAll();
                                layer.msg(res.msg);
                                layui.table.reload('CommentTable');
                            });
                        }
                    });
                }else{
                    layer.msg(res.msg);
                    layui.table.reload('CommentTable');
                }
            });
        });
    });
</script>
